//
//  ANewArrivalViewController.m
//  DistributorAB
//
//  Created by 主事丫环 on 2019/9/27.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ANewArrivalViewController.h"
#import "AGoodProductTableViewCell.h"
#import "AGoodProductModel.h"

@interface ANewArrivalViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *mytableView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *mydateSource;
@property (nonatomic, strong) UIView *tabFootView;
@property (nonatomic, strong) NSMutableSet <NSString *>*saoYiSaoStrSet;
@property (nonatomic, strong) UIView *bgViewsec;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, strong) NSMutableArray *modelArr;

@end

@implementation ANewArrivalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.page = 1;
    
    self.title = @"最新上架";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    
    self.mydateSource = [NSMutableArray arrayWithCapacity:1];
    self.modelArr = [NSMutableArray arrayWithCapacity:1];
    
    [self requestData];
    [self showdetaile];
    // Do any additional setup after loading the view.
}

-(void)showdetaile {
    
    [self.view addSubview:self.scrollView];
    
    _mytableView = [[UITableView alloc] init];
    _mytableView.frame = CGRectMake(0, kNaviHeight, KWIDTH, KHEIGHT-kNaviHeight);
    _mytableView.delegate = self;
    _mytableView.dataSource = self;
    _mytableView.estimatedRowHeight = 90;
    _mytableView.rowHeight = UITableViewAutomaticDimension;
    _mytableView.tableFooterView = [UIView new];
    
    [_mytableView registerClass:[AGoodProductTableViewCell class] forCellReuseIdentifier:@"AGoodProductTableViewCell"];
    
    _mytableView.backgroundColor = [UIColor clearColor];
    adjustInset(_mytableView);
    [_mytableView reloadData];
    [_scrollView addSubview:_mytableView];
}

- (void)requestData {
    //我要预订 数据请求
    
    if (_page == 1) {
        [_modelArr removeAllObjects];
    }
    
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    NSString *pp = [NSString stringWithFormat:@"%ld",(long)_page];
    param[@"pageNum"] = pp;
    param[@"type"] = @"3"; //我要预订 好物优选 3
    
    //    [NetWorkTool POST:getPartsList param:param success:^(id dic) {
    //        NSLog(@"有没有数据呀 %@", dic);
    //self.modelArr = [AGoodProductModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];

    //        [self.mytableView reloadData];
    //    } other:^(id dic) {
    //
    //    } fail:^(NSError *error) {
    //
    //    } needUser:NO];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return _modelArr.count;
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 345;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    //定义Cell标识 每一个Cell对应一个自己的标识
    NSString *CellIdentitier = [NSString stringWithFormat:@"cell%ld%ld",indexPath.section, indexPath.row];
    
    //通过唯一标识创建Cell实例
    AGoodProductTableViewCell *mycell = [tableView dequeueReusableCellWithIdentifier:CellIdentitier];
    //判断为空进行初始化  --(当拉动页面显示超过主页面内容的时候就会重用之前的cell,w而不会再次初始化)
    if (!mycell) {
        mycell = [[AGoodProductTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentitier];
    }
    self.mytableView.separatorStyle = UITableViewCellEditingStyleNone;//不显示分割线
    
    //    AGoodProductModel *model = self.modelArr[indexPath.row];
    //    [mycell.goodImg sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:nil]; //产品图片
    //    mycell.proTitLab.text = model.parts_name; //描述信息
    //    mycell.numTitLab.text = [NSString stringWithFormat:@"%@%@", model.cellCount,@"人预订"];
    
    return mycell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT)];
        _scrollView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        _scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(KWIDTH, 100);
        
        adjustInset(_scrollView);
    }
    return _scrollView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
